<template>
	<view class="content">
		<view class="card" v-for="(v,i) in newsList" :key="i" @click="naviageToPage('/pages/tree/homedetail?id='+v.id)">
			<image :src="v.banner" mode="aspectFill"></image>
			<view class="txtBox">
				{{v.title}}
			</view>
		</view>
		<empty v-if="newsList.length==0" />
	</view>
</template>

<script>
	import empty from "@/components/empty.vue"
	export default {
		components: {
			empty
		},
		data() {
			return {
				newsList: [],
			};
		},
		onShow() {
		},
		onLoad(options) {
			const that = this
			//2条新闻
			that.$api.request('news', 'list', {
				category: 1
			}, failres => {
				that.$api.msg(failres.errmsg)
			}).then(res => {
				console.log(res.data, '新闻')
				that.newsList = res.data.items
			})
		},
		onShareAppMessage() {
			const that = this
			return {
				title: '果王来了',
				imageUrl: 'https://shopmalling-asset.oss-cn-hangzhou.aliyuncs.com/share.jpg',
				path: '/pages/index/index'
			}
		},
		onPullDownRefresh() {
			console.log(123)
		},
		onReachBottom() {
			console.log(456)
		},
		methods: {
			gotoDetail(id) {
				uni.navigateTo({
					url: '/pages/tree/tree?id=' + id
				})
			},
			naviageToPage(page) {
				uni.navigateTo({
					url: page
				})
			},
		},
	}
</script>

<style lang="less" scoped>
	.content {
		.card {

			&:nth-child(n+2) {
				margin-top: 20upx;
			}

			image {
				width: 100%;
				height: 260upx;
				border-radius: 10upx;
			}

			.txtBox {
				padding: 20upx;
				background: #fff;
			}
		}
	}
</style>
